<template>
    <LModalForm 
        :visible="visible"
        :confirmLoading="confirmLoading" 
        :title="title" 
        ref="systemForm" 
        :formAttributes="formAttributes" 
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @clickEventHandler="clickEventHandler"
        @changeEventHandler="changeEventHandler"></LModalForm>

</template>

<script>
import LModalForm from "@/components/lt/form/LModalForm"
import pick from 'lodash.pick'
import request from '@/utils/request'
import defaultSettings from '@/config/defaultSettings'
export default {
    name:'systemForm',
    components:{
        LModalForm
    },
    data(){
        return{
            defaultSettings,
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'systemNo',label:'系统编号',component:'input',rules: [{required: true, message: '请输入系统编号'}]},
                    {field:'systemName',label:'系统名称',component:'input',rules: [{required: true, message: '请输入系统名称'}]},
                    {field:'systemUrl',label:'系统地址',component:'input'},
                    {field:'systemUse',label:'是否可用',component:'select',dictCode:defaultSettings.数据字典.是否}
                  ]
                },
              ]

            }


        }
    },
    methods:{
       
        edit (record) {
            
            this.visible = true;
            this.model = Object.assign({}, record);
            this.$nextTick(() => {
                this.$refs.systemForm.getForm().setFieldsValue(pick(this.model,'systemNo','systemName','systemUrl','systemUse'))
            })
        },
        handleOk(){
            const that = this;
            this.$refs.systemForm.getForm().validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/SysSystemController/save',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.close()
                            that.$message.success(res.message);
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                        
                    })
                    
                }
            })
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
        /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
            console.log(changeItem)
        },
        clickEventHandler(field,form){

        }
    },
    created(){
        
    },
}
</script>